/*
 *  ChordTester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 11/07/16.
 *  Copyright 2011 jiro music. All rights reserved.
 *
 */

#include "Theory0039_ChordTester.h"
#include "../Theory0039_Chord.h"
#include "../Theory0039_SingleGroupGenerator.h"

#include "../../../sc/Tester/CustomAssert.h"

using namespace sc;

namespace theory0039 {

	void ChordTester::TestAll()
	{
		Test_GetNoteCount();
		Test_GetIntervalCount();
		Test_GetIntervalOfIndex();
		Test_GetNoteIdsOfIntervalIndex();
		Test_IsIncludeNote();
		Test_GetNoteIndeciesOfIntervalIndex();
		Test_AreAllIntervalsSame();
	}

	void ChordTester::Test_GetNoteCount()
	{
		Chord c = Chord( Note::A );
		AssertEqual( c.GetNoteCount(), 1 );

		Chord c0 = Chord( Note::A, Note::B );
		AssertEqual( c0.GetNoteCount(), 2 );

		Chord c1 = Chord( Note::A, Note::B, Note::C );
		AssertEqual( c1.GetNoteCount(), 3 );

		Chord c2 = Chord( Note::A, Note::B, Note::C, Note::D );
		AssertEqual( c2.GetNoteCount(), 4 );

		Chord c3 = Chord( Note::A, Note::B, Note::C, Note::D, Note::E );
		AssertEqual( c3.GetNoteCount(), 5 );
	}

	void ChordTester::Test_GetIntervalCount()
	{
		Chord c = Chord( Note::A );
		AssertEqual( c.GetIntervalCount(), 1 );

		Chord c0 = Chord( Note::A, Note::B );
		AssertEqual( c0.GetIntervalCount(), 2 );

		Chord c1 = Chord( Note::A, Note::B, Note::C );
		AssertEqual( c1.GetIntervalCount(), 4 );

		Chord c2 = Chord( Note::A, Note::B, Note::C, Note::D );
		AssertEqual( c2.GetIntervalCount(), 7 );

		Chord c3 = Chord( Note::A, Note::B, Note::C, Note::D, Note::E );
		AssertEqual( c3.GetIntervalCount(), 11 );
	}

	void ChordTester::Test_GetIntervalOfIndex()
	{
		Chord c = Chord( Note::A, Note::B, Note::C );
		AssertEqual( c.GetIntervalOfIndex( 0 ), sc::Note::Perfect1st );
		AssertEqual( c.GetIntervalOfIndex( 1 ), sc::Note::Major2nd );
		AssertEqual( c.GetIntervalOfIndex( 2 ), sc::Note::Minor3rd );
		AssertEqual( c.GetIntervalOfIndex( 3 ), sc::Note::Minor2nd );
		
	}

	void ChordTester::Test_GetNoteIdsOfIntervalIndex()
	{
		Note::Id note0;
		Note::Id note1;

		Chord c0 = Chord( Note::A, Note::B, Note::C );
		c0.GetNoteIdsOfIntervalIndex( 0, note0, note1 );
		AssertEqual( note0, sc::Note::A );
		AssertEqual( note1, sc::Note::A );

		Chord c1 = Chord( Note::A, Note::B, Note::C );
		c1.GetNoteIdsOfIntervalIndex( 1, note0, note1 );
		AssertEqual( note0, sc::Note::A );
		AssertEqual( note1, sc::Note::B );

		c1.GetNoteIdsOfIntervalIndex( 2, note0, note1 );
		AssertEqual( note0, sc::Note::A );
		AssertEqual( note1, sc::Note::C );

		c1.GetNoteIdsOfIntervalIndex( 3, note0, note1 );
		AssertEqual( note0, sc::Note::B );
		AssertEqual( note1, sc::Note::C );
	}

	void ChordTester::Test_IsIncludeNote()
	{
		Chord c0 = Chord( Note::A, Note::B );
		AssertEqual( c0.IsIncludeNote( Note::A ), true );
		AssertEqual( c0.IsIncludeNote( Note::B ), true );
		AssertEqual( c0.IsIncludeNote( Note::C ), false );

	}

	void ChordTester::Test_GetNoteIndeciesOfIntervalIndex()
	{
		int index0;
		int index1;

		Chord c0 = Chord( Note::A, Note::B );
		c0.GetNoteIndeciesOfIntervalIndex( 1, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 1 );

		Chord c1 = Chord( Note::A, Note::B, Note::C );
		c1.GetNoteIndeciesOfIntervalIndex( 0, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 0 );
		c1.GetNoteIndeciesOfIntervalIndex( 1, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 1 );
		c1.GetNoteIndeciesOfIntervalIndex( 2, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 2 );
		c1.GetNoteIndeciesOfIntervalIndex( 3, index0, index1 );
		AssertEqual( index0, 1 );
		AssertEqual( index1, 2 );

		Chord c2 = Chord( Note::A, Note::B, Note::C, Note::D );
		c2.GetNoteIndeciesOfIntervalIndex( 0, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 0 );
		c2.GetNoteIndeciesOfIntervalIndex( 1, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 1 );
		c2.GetNoteIndeciesOfIntervalIndex( 2, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 2 );
		c2.GetNoteIndeciesOfIntervalIndex( 3, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 3 );
		c2.GetNoteIndeciesOfIntervalIndex( 4, index0, index1 );
		AssertEqual( index0, 1 );
		AssertEqual( index1, 2 );
		c2.GetNoteIndeciesOfIntervalIndex( 5, index0, index1 );
		AssertEqual( index0, 1 );
		AssertEqual( index1, 3 );
		c2.GetNoteIndeciesOfIntervalIndex( 6, index0, index1 );
		AssertEqual( index0, 2 );
		AssertEqual( index1, 3 );

		Chord c3 = Chord( Note::A, Note::B, Note::C, Note::D, Note::E );
		c3.GetNoteIndeciesOfIntervalIndex( 0, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 0 );
		c3.GetNoteIndeciesOfIntervalIndex( 1, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 1 );
		c3.GetNoteIndeciesOfIntervalIndex( 2, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 2 );
		c3.GetNoteIndeciesOfIntervalIndex( 3, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 3 );
		c3.GetNoteIndeciesOfIntervalIndex( 4, index0, index1 );
		AssertEqual( index0, 0 );
		AssertEqual( index1, 4 );
		c3.GetNoteIndeciesOfIntervalIndex( 5, index0, index1 );
		AssertEqual( index0, 1 );
		AssertEqual( index1, 2 );
		c3.GetNoteIndeciesOfIntervalIndex( 6, index0, index1 );
		AssertEqual( index0, 1 );
		AssertEqual( index1, 3 );
		c3.GetNoteIndeciesOfIntervalIndex( 7, index0, index1 );
		AssertEqual( index0, 1 );
		AssertEqual( index1, 4 );
		c3.GetNoteIndeciesOfIntervalIndex( 8, index0, index1 );
		AssertEqual( index0, 2 );
		AssertEqual( index1, 3 );
		c3.GetNoteIndeciesOfIntervalIndex( 9, index0, index1 );
		AssertEqual( index0, 2 );
		AssertEqual( index1, 4 );
		c3.GetNoteIndeciesOfIntervalIndex( 10, index0, index1 );
		AssertEqual( index0, 3 );
		AssertEqual( index1, 4 );
	}

	void ChordTester::Test_AreAllIntervalsSame()
	{
		Chord c0 = Chord( Note::A, Note::B, Note::C );
		Chord c1 = Chord( Note::A, Note::B, Note::C );		
		AssertTrue( c0.AreAllIntervalsSame( c1 ) );

		Chord c2 = Chord( Note::A, Note::B, Note::C );
		Chord c3 = Chord( Note::A, Note::G, Note::GFlat );		
		AssertFalse( c2.AreAllIntervalsSame( c3 ) );

		Chord c4 = Chord( Note::A, Note::A );
		Chord c5 = Chord( Note::A, Note::AFlat, Note::GFlat );		
		AssertTrue( c4.AreAllIntervalsSame( c5 ) );
	}

}